import {
    Entity,
    Column,
    ManyToOne,
    JoinColumn,
} from 'typeorm';
import { Base } from '../../../entities.base/base.entity';
import { Order } from '../order.entity';

@Entity('basis_order_group_buy_usage')
export class OrderGroupBuyUsage extends Base {
    @Column({
        type: 'decimal',
        precision: 10,
        scale: 2,
        comment: '团购支付金额（用于支付订单的金额）',
    })
    usedAmount: number;

    @Column({
        type: 'varchar',
        length: 50,
        comment: '团购平台（如美团、大众点评等）',
    })
    groupBuyPlatform: string;

    @Column({
        type: 'varchar',
        length: 100,
        comment: '团购订单号',
    })
    groupBuyOrderNumber: string;

    @Column({
        type: 'varchar',
        length: 100,
        nullable: true,
        comment: '团购券号',
    })
    groupBuyVoucherCode?: string;

    @Column({
        type: 'decimal',
        precision: 10,
        scale: 2,
        nullable: true,
        comment: '团购券原价（客户买团购卷的价格）',
    })
    originalPrice?: number;

    @Column({
        type: 'text',
        nullable: true,
        comment: '备注',
    })
    remark?: string;

    @Column({
        type: 'varchar',
        length: 36,
        comment: '订单ID',
    })
    orderId: string;

    // 关联关系
    @ManyToOne(() => Order, order => order.groupBuyUsages, {
        onDelete: 'CASCADE',
    })
    @JoinColumn({ name: 'orderId' })
    order: Order;
} 